/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.raitcon.hibernate.db;

import com.raitcon.hibernate.bean.CedulaMatricula;
import com.raitcon.hibernate.bean.Empleado;
import com.raitcon.hibernate.bean.Matricula;
import static com.raitcon.hibernate.db.EmpleadoDB.log;
import com.raitcon.hibernate.factory.HibernateUtil;
import java.util.List;
import org.apache.log4j.Logger;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author Mike
 */
public class MatriculaDB {
    
    protected static Logger log = Logger.getLogger(MatriculaDB.class);
    private Session session = null;
    
    
    public MatriculaDB() {
        this.session = HibernateUtil.getSessionFactory().getCurrentSession();
    }
    
     
    
    
    
    
     public List<Matricula> getMatriculaFilter(String idGradoSeccion,
             String idAnio, String idGrado, String state){
        
         log.info("Iniciando consulta de matricula...");
        List<Matricula> cedulaMatriculaList = null;
        try {
            Transaction tx = session.beginTransaction();
            Query q = session.createQuery("from Matricula as matricula WHERE (id_grado_seccion ="+idGradoSeccion
                    +" AND id_anio="+idAnio+ " AND id_grado="+idGrado+
                    " AND state='"+state+"')");

            cedulaMatriculaList = (List<Matricula>) q.list();
             log.info("Consulta de  matricula Exitosa.");
        } catch (Exception e) {
            log.error("Error:" + e.getMessage());
            e.printStackTrace();
        } finally {
            session.close();
        }
        return cedulaMatriculaList;
    }
    
     
     public List<CedulaMatricula> getCedulaMatriculaAll(){
        
         log.info("Iniciando consulta de Cedula de matricula...");
        List<CedulaMatricula> cedulaMatriculaList = null;
        try {
            Transaction tx = session.beginTransaction();
            Query q = session.createQuery("from Matricula as matricula" );
                   

            cedulaMatriculaList = (List<CedulaMatricula>) q.list();
             log.info("Consulta de Cedula de matricula Exitosa.");
        } catch (Exception e) {
            log.error("Error:" + e.getMessage());
            e.printStackTrace();
        } finally {
            session.close();
        }
        return cedulaMatriculaList;
    }
    
}
